{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2181bf76-bfb0-40db-9253-1b92f50d80ad",
   "metadata": {},
   "source": [
    "# pandas3 - 数据预处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "505c4906-500e-4617-b858-c5c6d985ce4b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ad43f58e-a2f0-4085-827e-d431e539ca03",
   "metadata": {},
   "source": [
    "## 数据重塑"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "97475e82-e2aa-40a9-8a5e-9911143e3964",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(     ename   job     mgr   sal    comm  dno\n",
       " eno                                        \n",
       " 1359   胡一刀   销售员  3344.0  1800   200.0   30\n",
       " 2056    乔峰   分析师  7800.0  5000  1500.0   20\n",
       " 3088   李莫愁   设计师  2056.0  3500   800.0   20\n",
       " 3211   张无忌   程序员  2056.0  3200     NaN   20\n",
       " 3233   丘处机   程序员  2056.0  3400     NaN   20\n",
       " 3244   欧阳锋   程序员  3088.0  3200     NaN   20\n",
       " 3251   张翠山   程序员  2056.0  4000     NaN   20\n",
       " 3344    黄蓉  销售主管  7800.0  3000   800.0   30\n",
       " 3577    杨过    会计  5566.0  2200     NaN   10\n",
       " 3588   朱九真    会计  5566.0  2500     NaN   10\n",
       " 4466   苗人凤   销售员  3344.0  2500     NaN   30\n",
       " 5234    郭靖    出纳  5566.0  2000     NaN   10\n",
       " 5566   宋远桥   会计师  7800.0  4000  1000.0   10\n",
       " 7800   张三丰    总裁     NaN  9000  1200.0   20,\n",
       "      ename  job     mgr    sal    comm  dno\n",
       " eno                                        \n",
       " 9500   张三丰   总裁     NaN  50000  8000.0   20\n",
       " 9600   王大锤  程序员  9800.0   8000   600.0   20\n",
       " 9700   张三丰   总裁     NaN  60000  6000.0   20\n",
       " 9800    骆昊  架构师  7800.0  30000  5000.0   20\n",
       " 9900   陈小刀  分析师  9800.0  10000  1200.0   20)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "emp_df = pd.read_csv('data/emp.csv', index_col='eno')\n",
    "emp2_df = pd.read_csv('data/emp2.csv', index_col='eno')\n",
    "emp_df, emp2_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "fe9466d5-c301-4ff0-8fea-33b84b02636d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ename</th>\n",
       "      <th>job</th>\n",
       "      <th>mgr</th>\n",
       "      <th>sal</th>\n",
       "      <th>comm</th>\n",
       "      <th>dno</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>eno</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1359</th>\n",
       "      <td>胡一刀</td>\n",
       "      <td>销售员</td>\n",
       "      <td>3344.0</td>\n",
       "      <td>1800</td>\n",
       "      <td>200.0</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2056</th>\n",
       "      <td>乔峰</td>\n",
       "      <td>分析师</td>\n",
       "      <td>7800.0</td>\n",
       "      <td>5000</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3088</th>\n",
       "      <td>李莫愁</td>\n",
       "      <td>设计师</td>\n",
       "      <td>2056.0</td>\n",
       "      <td>3500</td>\n",
       "      <td>800.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3211</th>\n",
       "      <td>张无忌</td>\n",
       "      <td>程序员</td>\n",
       "      <td>2056.0</td>\n",
       "      <td>3200</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3233</th>\n",
       "      <td>丘处机</td>\n",
       "      <td>程序员</td>\n",
       "      <td>2056.0</td>\n",
       "      <td>3400</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3244</th>\n",
       "      <td>欧阳锋</td>\n",
       "      <td>程序员</td>\n",
       "      <td>3088.0</td>\n",
       "      <td>3200</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3251</th>\n",
       "      <td>张翠山</td>\n",
       "      <td>程序员</td>\n",
       "      <td>2056.0</td>\n",
       "      <td>4000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3344</th>\n",
       "      <td>黄蓉</td>\n",
       "      <td>销售主管</td>\n",
       "      <td>7800.0</td>\n",
       "      <td>3000</td>\n",
       "      <td>800.0</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3577</th>\n",
       "      <td>杨过</td>\n",
       "      <td>会计</td>\n",
       "      <td>5566.0</td>\n",
       "      <td>2200</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3588</th>\n",
       "      <td>朱九真</td>\n",
       "      <td>会计</td>\n",
       "      <td>5566.0</td>\n",
       "      <td>2500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4466</th>\n",
       "      <td>苗人凤</td>\n",
       "      <td>销售员</td>\n",
       "      <td>3344.0</td>\n",
       "      <td>2500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5234</th>\n",
       "      <td>郭靖</td>\n",
       "      <td>出纳</td>\n",
       "      <td>5566.0</td>\n",
       "      <td>2000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5566</th>\n",
       "      <td>宋远桥</td>\n",
       "      <td>会计师</td>\n",
       "      <td>7800.0</td>\n",
       "      <td>4000</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7800</th>\n",
       "      <td>张三丰</td>\n",
       "      <td>总裁</td>\n",
       "      <td>NaN</td>\n",
       "      <td>9000</td>\n",
       "      <td>1200.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9500</th>\n",
       "      <td>张三丰</td>\n",
       "      <td>总裁</td>\n",
       "      <td>NaN</td>\n",
       "      <td>50000</td>\n",
       "      <td>8000.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9600</th>\n",
       "      <td>王大锤</td>\n",
       "      <td>程序员</td>\n",
       "      <td>9800.0</td>\n",
       "      <td>8000</td>\n",
       "      <td>600.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9700</th>\n",
       "      <td>张三丰</td>\n",
       "      <td>总裁</td>\n",
       "      <td>NaN</td>\n",
       "      <td>60000</td>\n",
       "      <td>6000.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9800</th>\n",
       "      <td>骆昊</td>\n",
       "      <td>架构师</td>\n",
       "      <td>7800.0</td>\n",
       "      <td>30000</td>\n",
       "      <td>5000.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9900</th>\n",
       "      <td>陈小刀</td>\n",
       "      <td>分析师</td>\n",
       "      <td>9800.0</td>\n",
       "      <td>10000</td>\n",
       "      <td>1200.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ename   job     mgr    sal    comm  dno\n",
       "eno                                         \n",
       "1359   胡一刀   销售员  3344.0   1800   200.0   30\n",
       "2056    乔峰   分析师  7800.0   5000  1500.0   20\n",
       "3088   李莫愁   设计师  2056.0   3500   800.0   20\n",
       "3211   张无忌   程序员  2056.0   3200     NaN   20\n",
       "3233   丘处机   程序员  2056.0   3400     NaN   20\n",
       "3244   欧阳锋   程序员  3088.0   3200     NaN   20\n",
       "3251   张翠山   程序员  2056.0   4000     NaN   20\n",
       "3344    黄蓉  销售主管  7800.0   3000   800.0   30\n",
       "3577    杨过    会计  5566.0   2200     NaN   10\n",
       "3588   朱九真    会计  5566.0   2500     NaN   10\n",
       "4466   苗人凤   销售员  3344.0   2500     NaN   30\n",
       "5234    郭靖    出纳  5566.0   2000     NaN   10\n",
       "5566   宋远桥   会计师  7800.0   4000  1000.0   10\n",
       "7800   张三丰    总裁     NaN   9000  1200.0   20\n",
       "9500   张三丰    总裁     NaN  50000  8000.0   20\n",
       "9600   王大锤   程序员  9800.0   8000   600.0   20\n",
       "9700   张三丰    总裁     NaN  60000  6000.0   20\n",
       "9800    骆昊   架构师  7800.0  30000  5000.0   20\n",
       "9900   陈小刀   分析师  9800.0  10000  1200.0   20"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 拼接DataFrame\n",
    "all_emp_df = pd.concat([emp_df, emp2_df])\n",
    "all_emp_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ec028326-a03b-47ba-bb34-dce47cb9827b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>eno</th>\n",
       "      <th>ename</th>\n",
       "      <th>job</th>\n",
       "      <th>mgr</th>\n",
       "      <th>sal</th>\n",
       "      <th>comm</th>\n",
       "      <th>dno</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1359</td>\n",
       "      <td>胡一刀</td>\n",
       "      <td>销售员</td>\n",
       "      <td>3344.0</td>\n",
       "      <td>1800</td>\n",
       "      <td>200.0</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2056</td>\n",
       "      <td>乔峰</td>\n",
       "      <td>分析师</td>\n",
       "      <td>7800.0</td>\n",
       "      <td>5000</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3088</td>\n",
       "      <td>李莫愁</td>\n",
       "      <td>设计师</td>\n",
       "      <td>2056.0</td>\n",
       "      <td>3500</td>\n",
       "      <td>800.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3211</td>\n",
       "      <td>张无忌</td>\n",
       "      <td>程序员</td>\n",
       "      <td>2056.0</td>\n",
       "      <td>3200</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3233</td>\n",
       "      <td>丘处机</td>\n",
       "      <td>程序员</td>\n",
       "      <td>2056.0</td>\n",
       "      <td>3400</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>3244</td>\n",
       "      <td>欧阳锋</td>\n",
       "      <td>程序员</td>\n",
       "      <td>3088.0</td>\n",
       "      <td>3200</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>3251</td>\n",
       "      <td>张翠山</td>\n",
       "      <td>程序员</td>\n",
       "      <td>2056.0</td>\n",
       "      <td>4000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>3344</td>\n",
       "      <td>黄蓉</td>\n",
       "      <td>销售主管</td>\n",
       "      <td>7800.0</td>\n",
       "      <td>3000</td>\n",
       "      <td>800.0</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>3577</td>\n",
       "      <td>杨过</td>\n",
       "      <td>会计</td>\n",
       "      <td>5566.0</td>\n",
       "      <td>2200</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>3588</td>\n",
       "      <td>朱九真</td>\n",
       "      <td>会计</td>\n",
       "      <td>5566.0</td>\n",
       "      <td>2500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>4466</td>\n",
       "      <td>苗人凤</td>\n",
       "      <td>销售员</td>\n",
       "      <td>3344.0</td>\n",
       "      <td>2500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>5234</td>\n",
       "      <td>郭靖</td>\n",
       "      <td>出纳</td>\n",
       "      <td>5566.0</td>\n",
       "      <td>2000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>5566</td>\n",
       "      <td>宋远桥</td>\n",
       "      <td>会计师</td>\n",
       "      <td>7800.0</td>\n",
       "      <td>4000</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>7800</td>\n",
       "      <td>张三丰</td>\n",
       "      <td>总裁</td>\n",
       "      <td>NaN</td>\n",
       "      <td>9000</td>\n",
       "      <td>1200.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>9500</td>\n",
       "      <td>张三丰</td>\n",
       "      <td>总裁</td>\n",
       "      <td>NaN</td>\n",
       "      <td>50000</td>\n",
       "      <td>8000.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>9600</td>\n",
       "      <td>王大锤</td>\n",
       "      <td>程序员</td>\n",
       "      <td>9800.0</td>\n",
       "      <td>8000</td>\n",
       "      <td>600.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>9700</td>\n",
       "      <td>张三丰</td>\n",
       "      <td>总裁</td>\n",
       "      <td>NaN</td>\n",
       "      <td>60000</td>\n",
       "      <td>6000.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>9800</td>\n",
       "      <td>骆昊</td>\n",
       "      <td>架构师</td>\n",
       "      <td>7800.0</td>\n",
       "      <td>30000</td>\n",
       "      <td>5000.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>9900</td>\n",
       "      <td>陈小刀</td>\n",
       "      <td>分析师</td>\n",
       "      <td>9800.0</td>\n",
       "      <td>10000</td>\n",
       "      <td>1200.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     eno ename   job     mgr    sal    comm  dno\n",
       "0   1359   胡一刀   销售员  3344.0   1800   200.0   30\n",
       "1   2056    乔峰   分析师  7800.0   5000  1500.0   20\n",
       "2   3088   李莫愁   设计师  2056.0   3500   800.0   20\n",
       "3   3211   张无忌   程序员  2056.0   3200     NaN   20\n",
       "4   3233   丘处机   程序员  2056.0   3400     NaN   20\n",
       "5   3244   欧阳锋   程序员  3088.0   3200     NaN   20\n",
       "6   3251   张翠山   程序员  2056.0   4000     NaN   20\n",
       "7   3344    黄蓉  销售主管  7800.0   3000   800.0   30\n",
       "8   3577    杨过    会计  5566.0   2200     NaN   10\n",
       "9   3588   朱九真    会计  5566.0   2500     NaN   10\n",
       "10  4466   苗人凤   销售员  3344.0   2500     NaN   30\n",
       "11  5234    郭靖    出纳  5566.0   2000     NaN   10\n",
       "12  5566   宋远桥   会计师  7800.0   4000  1000.0   10\n",
       "13  7800   张三丰    总裁     NaN   9000  1200.0   20\n",
       "14  9500   张三丰    总裁     NaN  50000  8000.0   20\n",
       "15  9600   王大锤   程序员  9800.0   8000   600.0   20\n",
       "16  9700   张三丰    总裁     NaN  60000  6000.0   20\n",
       "17  9800    骆昊   架构师  7800.0  30000  5000.0   20\n",
       "18  9900   陈小刀   分析师  9800.0  10000  1200.0   20"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 重置索引\n",
    "all_emp_df.reset_index(inplace=True)\n",
    "all_emp_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "bad5d0b3-cbd6-4c44-acf7-8b42fa81cbe4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>dname</th>\n",
       "      <th>dloc</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>dno</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>会计部</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>研发部</td>\n",
       "      <td>成都</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>销售部</td>\n",
       "      <td>重庆</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>运维部</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    dname dloc\n",
       "dno           \n",
       "10    会计部   北京\n",
       "20    研发部   成都\n",
       "30    销售部   重庆\n",
       "40    运维部   深圳"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dept_df = pd.read_csv('data/dept.csv', index_col='dno')\n",
    "dept_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "97965dab-5f3d-47d4-91b4-4c987dc5daf4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>eno</th>\n",
       "      <th>ename</th>\n",
       "      <th>job</th>\n",
       "      <th>mgr</th>\n",
       "      <th>sal</th>\n",
       "      <th>comm</th>\n",
       "      <th>dno</th>\n",
       "      <th>dname</th>\n",
       "      <th>dloc</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1359</td>\n",
       "      <td>胡一刀</td>\n",
       "      <td>销售员</td>\n",
       "      <td>3344.0</td>\n",
       "      <td>1800</td>\n",
       "      <td>200.0</td>\n",
       "      <td>30</td>\n",
       "      <td>销售部</td>\n",
       "      <td>重庆</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2056</td>\n",
       "      <td>乔峰</td>\n",
       "      <td>分析师</td>\n",
       "      <td>7800.0</td>\n",
       "      <td>5000</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>20</td>\n",
       "      <td>研发部</td>\n",
       "      <td>成都</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3088</td>\n",
       "      <td>李莫愁</td>\n",
       "      <td>设计师</td>\n",
       "      <td>2056.0</td>\n",
       "      <td>3500</td>\n",
       "      <td>800.0</td>\n",
       "      <td>20</td>\n",
       "      <td>研发部</td>\n",
       "      <td>成都</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3211</td>\n",
       "      <td>张无忌</td>\n",
       "      <td>程序员</td>\n",
       "      <td>2056.0</td>\n",
       "      <td>3200</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20</td>\n",
       "      <td>研发部</td>\n",
       "      <td>成都</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3233</td>\n",
       "      <td>丘处机</td>\n",
       "      <td>程序员</td>\n",
       "      <td>2056.0</td>\n",
       "      <td>3400</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20</td>\n",
       "      <td>研发部</td>\n",
       "      <td>成都</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>3244</td>\n",
       "      <td>欧阳锋</td>\n",
       "      <td>程序员</td>\n",
       "      <td>3088.0</td>\n",
       "      <td>3200</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20</td>\n",
       "      <td>研发部</td>\n",
       "      <td>成都</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>3251</td>\n",
       "      <td>张翠山</td>\n",
       "      <td>程序员</td>\n",
       "      <td>2056.0</td>\n",
       "      <td>4000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20</td>\n",
       "      <td>研发部</td>\n",
       "      <td>成都</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>3344</td>\n",
       "      <td>黄蓉</td>\n",
       "      <td>销售主管</td>\n",
       "      <td>7800.0</td>\n",
       "      <td>3000</td>\n",
       "      <td>800.0</td>\n",
       "      <td>30</td>\n",
       "      <td>销售部</td>\n",
       "      <td>重庆</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>3577</td>\n",
       "      <td>杨过</td>\n",
       "      <td>会计</td>\n",
       "      <td>5566.0</td>\n",
       "      <td>2200</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10</td>\n",
       "      <td>会计部</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>3588</td>\n",
       "      <td>朱九真</td>\n",
       "      <td>会计</td>\n",
       "      <td>5566.0</td>\n",
       "      <td>2500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10</td>\n",
       "      <td>会计部</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>4466</td>\n",
       "      <td>苗人凤</td>\n",
       "      <td>销售员</td>\n",
       "      <td>3344.0</td>\n",
       "      <td>2500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>30</td>\n",
       "      <td>销售部</td>\n",
       "      <td>重庆</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>5234</td>\n",
       "      <td>郭靖</td>\n",
       "      <td>出纳</td>\n",
       "      <td>5566.0</td>\n",
       "      <td>2000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10</td>\n",
       "      <td>会计部</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>5566</td>\n",
       "      <td>宋远桥</td>\n",
       "      <td>会计师</td>\n",
       "      <td>7800.0</td>\n",
       "      <td>4000</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>10</td>\n",
       "      <td>会计部</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>7800</td>\n",
       "      <td>张三丰</td>\n",
       "      <td>总裁</td>\n",
       "      <td>NaN</td>\n",
       "      <td>9000</td>\n",
       "      <td>1200.0</td>\n",
       "      <td>20</td>\n",
       "      <td>研发部</td>\n",
       "      <td>成都</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>9500</td>\n",
       "      <td>张三丰</td>\n",
       "      <td>总裁</td>\n",
       "      <td>NaN</td>\n",
       "      <td>50000</td>\n",
       "      <td>8000.0</td>\n",
       "      <td>20</td>\n",
       "      <td>研发部</td>\n",
       "      <td>成都</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>9600</td>\n",
       "      <td>王大锤</td>\n",
       "      <td>程序员</td>\n",
       "      <td>9800.0</td>\n",
       "      <td>8000</td>\n",
       "      <td>600.0</td>\n",
       "      <td>20</td>\n",
       "      <td>研发部</td>\n",
       "      <td>成都</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>9700</td>\n",
       "      <td>张三丰</td>\n",
       "      <td>总裁</td>\n",
       "      <td>NaN</td>\n",
       "      <td>60000</td>\n",
       "      <td>6000.0</td>\n",
       "      <td>20</td>\n",
       "      <td>研发部</td>\n",
       "      <td>成都</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>9800</td>\n",
       "      <td>骆昊</td>\n",
       "      <td>架构师</td>\n",
       "      <td>7800.0</td>\n",
       "      <td>30000</td>\n",
       "      <td>5000.0</td>\n",
       "      <td>20</td>\n",
       "      <td>研发部</td>\n",
       "      <td>成都</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>9900</td>\n",
       "      <td>陈小刀</td>\n",
       "      <td>分析师</td>\n",
       "      <td>9800.0</td>\n",
       "      <td>10000</td>\n",
       "      <td>1200.0</td>\n",
       "      <td>20</td>\n",
       "      <td>研发部</td>\n",
       "      <td>成都</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     eno ename   job     mgr    sal    comm  dno dname dloc\n",
       "0   1359   胡一刀   销售员  3344.0   1800   200.0   30   销售部   重庆\n",
       "1   2056    乔峰   分析师  7800.0   5000  1500.0   20   研发部   成都\n",
       "2   3088   李莫愁   设计师  2056.0   3500   800.0   20   研发部   成都\n",
       "3   3211   张无忌   程序员  2056.0   3200     NaN   20   研发部   成都\n",
       "4   3233   丘处机   程序员  2056.0   3400     NaN   20   研发部   成都\n",
       "5   3244   欧阳锋   程序员  3088.0   3200     NaN   20   研发部   成都\n",
       "6   3251   张翠山   程序员  2056.0   4000     NaN   20   研发部   成都\n",
       "7   3344    黄蓉  销售主管  7800.0   3000   800.0   30   销售部   重庆\n",
       "8   3577    杨过    会计  5566.0   2200     NaN   10   会计部   北京\n",
       "9   3588   朱九真    会计  5566.0   2500     NaN   10   会计部   北京\n",
       "10  4466   苗人凤   销售员  3344.0   2500     NaN   30   销售部   重庆\n",
       "11  5234    郭靖    出纳  5566.0   2000     NaN   10   会计部   北京\n",
       "12  5566   宋远桥   会计师  7800.0   4000  1000.0   10   会计部   北京\n",
       "13  7800   张三丰    总裁     NaN   9000  1200.0   20   研发部   成都\n",
       "14  9500   张三丰    总裁     NaN  50000  8000.0   20   研发部   成都\n",
       "15  9600   王大锤   程序员  9800.0   8000   600.0   20   研发部   成都\n",
       "16  9700   张三丰    总裁     NaN  60000  6000.0   20   研发部   成都\n",
       "17  9800    骆昊   架构师  7800.0  30000  5000.0   20   研发部   成都\n",
       "18  9900   陈小刀   分析师  9800.0  10000  1200.0   20   研发部   成都"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 合并，类似于sql语句的多表查询\n",
    "# 前两个参数是左表和右表\n",
    "# how是JOIN的方式\n",
    "pd.merge(all_emp_df, dept_df, how='inner', on='dno')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8d37343a-e8b0-49b8-8d93-b8dd7ce3eec2",
   "metadata": {},
   "source": [
    "## 数据清洗\n",
    "\n",
    "### 缺失值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "bb25321a-0d08-4dfc-943c-5a03659dd740",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ename</th>\n",
       "      <th>job</th>\n",
       "      <th>mgr</th>\n",
       "      <th>sal</th>\n",
       "      <th>comm</th>\n",
       "      <th>dno</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>eno</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1359</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2056</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3088</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3211</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3233</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3244</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3251</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3344</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3577</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3588</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4466</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5234</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5566</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7800</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      ename    job    mgr    sal   comm    dno\n",
       "eno                                           \n",
       "1359  False  False  False  False  False  False\n",
       "2056  False  False  False  False  False  False\n",
       "3088  False  False  False  False  False  False\n",
       "3211  False  False  False  False   True  False\n",
       "3233  False  False  False  False   True  False\n",
       "3244  False  False  False  False   True  False\n",
       "3251  False  False  False  False   True  False\n",
       "3344  False  False  False  False  False  False\n",
       "3577  False  False  False  False   True  False\n",
       "3588  False  False  False  False   True  False\n",
       "4466  False  False  False  False   True  False\n",
       "5234  False  False  False  False   True  False\n",
       "5566  False  False  False  False  False  False\n",
       "7800  False  False   True  False  False  False"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 检查缺失值\n",
    "emp_df.isnull()\n",
    "# 也可使用\n",
    "# emp_df.isna()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "4e4e2c0e-7af8-419e-b241-40d8430c91fd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ename</th>\n",
       "      <th>job</th>\n",
       "      <th>mgr</th>\n",
       "      <th>sal</th>\n",
       "      <th>comm</th>\n",
       "      <th>dno</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>eno</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1359</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2056</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3088</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3211</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3233</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3244</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3251</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3344</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3577</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3588</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4466</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5234</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5566</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7800</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      ename   job    mgr   sal   comm   dno\n",
       "eno                                        \n",
       "1359   True  True   True  True   True  True\n",
       "2056   True  True   True  True   True  True\n",
       "3088   True  True   True  True   True  True\n",
       "3211   True  True   True  True  False  True\n",
       "3233   True  True   True  True  False  True\n",
       "3244   True  True   True  True  False  True\n",
       "3251   True  True   True  True  False  True\n",
       "3344   True  True   True  True   True  True\n",
       "3577   True  True   True  True  False  True\n",
       "3588   True  True   True  True  False  True\n",
       "4466   True  True   True  True  False  True\n",
       "5234   True  True   True  True  False  True\n",
       "5566   True  True   True  True   True  True\n",
       "7800   True  True  False  True   True  True"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 检查非缺失值\n",
    "emp_df.notna()\n",
    "# 也可使用\n",
    "# emp_df.notnull()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "f5809f54-510e-4c7c-ad90-624efa2ecf61",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ename</th>\n",
       "      <th>job</th>\n",
       "      <th>mgr</th>\n",
       "      <th>sal</th>\n",
       "      <th>comm</th>\n",
       "      <th>dno</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>eno</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1359</th>\n",
       "      <td>胡一刀</td>\n",
       "      <td>销售员</td>\n",
       "      <td>3344.0</td>\n",
       "      <td>1800</td>\n",
       "      <td>200.0</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2056</th>\n",
       "      <td>乔峰</td>\n",
       "      <td>分析师</td>\n",
       "      <td>7800.0</td>\n",
       "      <td>5000</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3088</th>\n",
       "      <td>李莫愁</td>\n",
       "      <td>设计师</td>\n",
       "      <td>2056.0</td>\n",
       "      <td>3500</td>\n",
       "      <td>800.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3344</th>\n",
       "      <td>黄蓉</td>\n",
       "      <td>销售主管</td>\n",
       "      <td>7800.0</td>\n",
       "      <td>3000</td>\n",
       "      <td>800.0</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5566</th>\n",
       "      <td>宋远桥</td>\n",
       "      <td>会计师</td>\n",
       "      <td>7800.0</td>\n",
       "      <td>4000</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ename   job     mgr   sal    comm  dno\n",
       "eno                                        \n",
       "1359   胡一刀   销售员  3344.0  1800   200.0   30\n",
       "2056    乔峰   分析师  7800.0  5000  1500.0   20\n",
       "3088   李莫愁   设计师  2056.0  3500   800.0   20\n",
       "3344    黄蓉  销售主管  7800.0  3000   800.0   30\n",
       "5566   宋远桥   会计师  7800.0  4000  1000.0   10"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 删除缺失值\n",
    "# 默认沿着0轴删除\n",
    "emp_df.dropna()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "87729ebb-5d18-4429-8057-976d40c0a7f1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ename</th>\n",
       "      <th>job</th>\n",
       "      <th>sal</th>\n",
       "      <th>dno</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>eno</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1359</th>\n",
       "      <td>胡一刀</td>\n",
       "      <td>销售员</td>\n",
       "      <td>1800</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2056</th>\n",
       "      <td>乔峰</td>\n",
       "      <td>分析师</td>\n",
       "      <td>5000</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3088</th>\n",
       "      <td>李莫愁</td>\n",
       "      <td>设计师</td>\n",
       "      <td>3500</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3211</th>\n",
       "      <td>张无忌</td>\n",
       "      <td>程序员</td>\n",
       "      <td>3200</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3233</th>\n",
       "      <td>丘处机</td>\n",
       "      <td>程序员</td>\n",
       "      <td>3400</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3244</th>\n",
       "      <td>欧阳锋</td>\n",
       "      <td>程序员</td>\n",
       "      <td>3200</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3251</th>\n",
       "      <td>张翠山</td>\n",
       "      <td>程序员</td>\n",
       "      <td>4000</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3344</th>\n",
       "      <td>黄蓉</td>\n",
       "      <td>销售主管</td>\n",
       "      <td>3000</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3577</th>\n",
       "      <td>杨过</td>\n",
       "      <td>会计</td>\n",
       "      <td>2200</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3588</th>\n",
       "      <td>朱九真</td>\n",
       "      <td>会计</td>\n",
       "      <td>2500</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4466</th>\n",
       "      <td>苗人凤</td>\n",
       "      <td>销售员</td>\n",
       "      <td>2500</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5234</th>\n",
       "      <td>郭靖</td>\n",
       "      <td>出纳</td>\n",
       "      <td>2000</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5566</th>\n",
       "      <td>宋远桥</td>\n",
       "      <td>会计师</td>\n",
       "      <td>4000</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7800</th>\n",
       "      <td>张三丰</td>\n",
       "      <td>总裁</td>\n",
       "      <td>9000</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ename   job   sal  dno\n",
       "eno                        \n",
       "1359   胡一刀   销售员  1800   30\n",
       "2056    乔峰   分析师  5000   20\n",
       "3088   李莫愁   设计师  3500   20\n",
       "3211   张无忌   程序员  3200   20\n",
       "3233   丘处机   程序员  3400   20\n",
       "3244   欧阳锋   程序员  3200   20\n",
       "3251   张翠山   程序员  4000   20\n",
       "3344    黄蓉  销售主管  3000   30\n",
       "3577    杨过    会计  2200   10\n",
       "3588   朱九真    会计  2500   10\n",
       "4466   苗人凤   销售员  2500   30\n",
       "5234    郭靖    出纳  2000   10\n",
       "5566   宋远桥   会计师  4000   10\n",
       "7800   张三丰    总裁  9000   20"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 沿着1轴删除缺失值\n",
    "emp_df.dropna(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "bdc37fa5-b684-4b52-a004-17e09f9ba412",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ename</th>\n",
       "      <th>job</th>\n",
       "      <th>mgr</th>\n",
       "      <th>sal</th>\n",
       "      <th>comm</th>\n",
       "      <th>dno</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>eno</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1359</th>\n",
       "      <td>胡一刀</td>\n",
       "      <td>销售员</td>\n",
       "      <td>3344.0</td>\n",
       "      <td>1800</td>\n",
       "      <td>200.0</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2056</th>\n",
       "      <td>乔峰</td>\n",
       "      <td>分析师</td>\n",
       "      <td>7800.0</td>\n",
       "      <td>5000</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3088</th>\n",
       "      <td>李莫愁</td>\n",
       "      <td>设计师</td>\n",
       "      <td>2056.0</td>\n",
       "      <td>3500</td>\n",
       "      <td>800.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3211</th>\n",
       "      <td>张无忌</td>\n",
       "      <td>程序员</td>\n",
       "      <td>2056.0</td>\n",
       "      <td>3200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3233</th>\n",
       "      <td>丘处机</td>\n",
       "      <td>程序员</td>\n",
       "      <td>2056.0</td>\n",
       "      <td>3400</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3244</th>\n",
       "      <td>欧阳锋</td>\n",
       "      <td>程序员</td>\n",
       "      <td>3088.0</td>\n",
       "      <td>3200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3251</th>\n",
       "      <td>张翠山</td>\n",
       "      <td>程序员</td>\n",
       "      <td>2056.0</td>\n",
       "      <td>4000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3344</th>\n",
       "      <td>黄蓉</td>\n",
       "      <td>销售主管</td>\n",
       "      <td>7800.0</td>\n",
       "      <td>3000</td>\n",
       "      <td>800.0</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3577</th>\n",
       "      <td>杨过</td>\n",
       "      <td>会计</td>\n",
       "      <td>5566.0</td>\n",
       "      <td>2200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3588</th>\n",
       "      <td>朱九真</td>\n",
       "      <td>会计</td>\n",
       "      <td>5566.0</td>\n",
       "      <td>2500</td>\n",
       "      <td>0.0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4466</th>\n",
       "      <td>苗人凤</td>\n",
       "      <td>销售员</td>\n",
       "      <td>3344.0</td>\n",
       "      <td>2500</td>\n",
       "      <td>0.0</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5234</th>\n",
       "      <td>郭靖</td>\n",
       "      <td>出纳</td>\n",
       "      <td>5566.0</td>\n",
       "      <td>2000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5566</th>\n",
       "      <td>宋远桥</td>\n",
       "      <td>会计师</td>\n",
       "      <td>7800.0</td>\n",
       "      <td>4000</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7800</th>\n",
       "      <td>张三丰</td>\n",
       "      <td>总裁</td>\n",
       "      <td>0.0</td>\n",
       "      <td>9000</td>\n",
       "      <td>1200.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ename   job     mgr   sal    comm  dno\n",
       "eno                                        \n",
       "1359   胡一刀   销售员  3344.0  1800   200.0   30\n",
       "2056    乔峰   分析师  7800.0  5000  1500.0   20\n",
       "3088   李莫愁   设计师  2056.0  3500   800.0   20\n",
       "3211   张无忌   程序员  2056.0  3200     0.0   20\n",
       "3233   丘处机   程序员  2056.0  3400     0.0   20\n",
       "3244   欧阳锋   程序员  3088.0  3200     0.0   20\n",
       "3251   张翠山   程序员  2056.0  4000     0.0   20\n",
       "3344    黄蓉  销售主管  7800.0  3000   800.0   30\n",
       "3577    杨过    会计  5566.0  2200     0.0   10\n",
       "3588   朱九真    会计  5566.0  2500     0.0   10\n",
       "4466   苗人凤   销售员  3344.0  2500     0.0   30\n",
       "5234    郭靖    出纳  5566.0  2000     0.0   10\n",
       "5566   宋远桥   会计师  7800.0  4000  1000.0   10\n",
       "7800   张三丰    总裁     0.0  9000  1200.0   20"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 用0填充空值\n",
    "emp_df.fillna(value=0)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "283bbdcf-a6e4-4355-b572-4e686dfa595a",
   "metadata": {},
   "source": [
    "### 重复值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "cfa6ce19-e4f8-46d6-8d20-8404ffbfbdce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>dname</th>\n",
       "      <th>dloc</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>dno</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>会计部</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>研发部</td>\n",
       "      <td>成都</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>销售部</td>\n",
       "      <td>重庆</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>运维部</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    dname dloc\n",
       "dno           \n",
       "10    会计部   北京\n",
       "20    研发部   成都\n",
       "30    销售部   重庆\n",
       "40    运维部   深圳"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dept_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "400446c2-a9c7-4b57-b8d2-cedbfe13e6bc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>dname</th>\n",
       "      <th>dloc</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>dno</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>会计部</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>研发部</td>\n",
       "      <td>成都</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>销售部</td>\n",
       "      <td>重庆</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>运维部</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>研发部</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>销售部</td>\n",
       "      <td>长沙</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    dname dloc\n",
       "dno           \n",
       "10    会计部   北京\n",
       "20    研发部   成都\n",
       "30    销售部   重庆\n",
       "40    运维部   深圳\n",
       "50    研发部   上海\n",
       "60    销售部   长沙"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dept_df.loc[50] = {'dname': '研发部', 'dloc': '上海'}\n",
    "dept_df.loc[60] = {'dname': '销售部', 'dloc': '长沙'}\n",
    "dept_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "4bea7dea-e2d8-4ea2-b0de-ccfbcb19c7f6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dno\n",
       "10    False\n",
       "20    False\n",
       "30    False\n",
       "40    False\n",
       "50     True\n",
       "60     True\n",
       "dtype: bool"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 判断指定列是否有重复值\n",
    "dept_df.duplicated('dname')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "1bafed02-47e4-4db7-948b-af11e29fe894",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>dname</th>\n",
       "      <th>dloc</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>dno</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>会计部</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>研发部</td>\n",
       "      <td>成都</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>销售部</td>\n",
       "      <td>重庆</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>运维部</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    dname dloc\n",
       "dno           \n",
       "10    会计部   北京\n",
       "20    研发部   成都\n",
       "30    销售部   重庆\n",
       "40    运维部   深圳"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 删除重复值，默认保留第一项\n",
    "dept_df.drop_duplicates('dname')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "b644d6b7-73b2-42a6-a89e-d756568e162d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>dname</th>\n",
       "      <th>dloc</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>dno</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>会计部</td>\n",
       "      <td>北京</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>运维部</td>\n",
       "      <td>深圳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>研发部</td>\n",
       "      <td>上海</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>销售部</td>\n",
       "      <td>长沙</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    dname dloc\n",
       "dno           \n",
       "10    会计部   北京\n",
       "40    运维部   深圳\n",
       "50    研发部   上海\n",
       "60    销售部   长沙"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 删除重复值，保留最后一项\n",
    "dept_df.drop_duplicates('dname', keep='last')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "fb23ac4c-27ff-4c96-a75f-9c4b3449c6c8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>eno</th>\n",
       "      <th>ename</th>\n",
       "      <th>job</th>\n",
       "      <th>mgr</th>\n",
       "      <th>sal</th>\n",
       "      <th>comm</th>\n",
       "      <th>dno</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1359</td>\n",
       "      <td>胡一刀</td>\n",
       "      <td>销售员</td>\n",
       "      <td>3344.0</td>\n",
       "      <td>1800</td>\n",
       "      <td>200.0</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2056</td>\n",
       "      <td>乔峰</td>\n",
       "      <td>分析师</td>\n",
       "      <td>7800.0</td>\n",
       "      <td>5000</td>\n",
       "      <td>1500.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3088</td>\n",
       "      <td>李莫愁</td>\n",
       "      <td>设计师</td>\n",
       "      <td>2056.0</td>\n",
       "      <td>3500</td>\n",
       "      <td>800.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3211</td>\n",
       "      <td>张无忌</td>\n",
       "      <td>程序员</td>\n",
       "      <td>2056.0</td>\n",
       "      <td>3200</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3233</td>\n",
       "      <td>丘处机</td>\n",
       "      <td>程序员</td>\n",
       "      <td>2056.0</td>\n",
       "      <td>3400</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>3244</td>\n",
       "      <td>欧阳锋</td>\n",
       "      <td>程序员</td>\n",
       "      <td>3088.0</td>\n",
       "      <td>3200</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>3251</td>\n",
       "      <td>张翠山</td>\n",
       "      <td>程序员</td>\n",
       "      <td>2056.0</td>\n",
       "      <td>4000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>3344</td>\n",
       "      <td>黄蓉</td>\n",
       "      <td>销售主管</td>\n",
       "      <td>7800.0</td>\n",
       "      <td>3000</td>\n",
       "      <td>800.0</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>3577</td>\n",
       "      <td>杨过</td>\n",
       "      <td>会计</td>\n",
       "      <td>5566.0</td>\n",
       "      <td>2200</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>3588</td>\n",
       "      <td>朱九真</td>\n",
       "      <td>会计</td>\n",
       "      <td>5566.0</td>\n",
       "      <td>2500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>4466</td>\n",
       "      <td>苗人凤</td>\n",
       "      <td>销售员</td>\n",
       "      <td>3344.0</td>\n",
       "      <td>2500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>5234</td>\n",
       "      <td>郭靖</td>\n",
       "      <td>出纳</td>\n",
       "      <td>5566.0</td>\n",
       "      <td>2000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>5566</td>\n",
       "      <td>宋远桥</td>\n",
       "      <td>会计师</td>\n",
       "      <td>7800.0</td>\n",
       "      <td>4000</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>7800</td>\n",
       "      <td>张三丰</td>\n",
       "      <td>总裁</td>\n",
       "      <td>NaN</td>\n",
       "      <td>9000</td>\n",
       "      <td>1200.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>9600</td>\n",
       "      <td>王大锤</td>\n",
       "      <td>程序员</td>\n",
       "      <td>9800.0</td>\n",
       "      <td>8000</td>\n",
       "      <td>600.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>9800</td>\n",
       "      <td>骆昊</td>\n",
       "      <td>架构师</td>\n",
       "      <td>7800.0</td>\n",
       "      <td>30000</td>\n",
       "      <td>5000.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>9900</td>\n",
       "      <td>陈小刀</td>\n",
       "      <td>分析师</td>\n",
       "      <td>9800.0</td>\n",
       "      <td>10000</td>\n",
       "      <td>1200.0</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     eno ename   job     mgr    sal    comm  dno\n",
       "0   1359   胡一刀   销售员  3344.0   1800   200.0   30\n",
       "1   2056    乔峰   分析师  7800.0   5000  1500.0   20\n",
       "2   3088   李莫愁   设计师  2056.0   3500   800.0   20\n",
       "3   3211   张无忌   程序员  2056.0   3200     NaN   20\n",
       "4   3233   丘处机   程序员  2056.0   3400     NaN   20\n",
       "5   3244   欧阳锋   程序员  3088.0   3200     NaN   20\n",
       "6   3251   张翠山   程序员  2056.0   4000     NaN   20\n",
       "7   3344    黄蓉  销售主管  7800.0   3000   800.0   30\n",
       "8   3577    杨过    会计  5566.0   2200     NaN   10\n",
       "9   3588   朱九真    会计  5566.0   2500     NaN   10\n",
       "10  4466   苗人凤   销售员  3344.0   2500     NaN   30\n",
       "11  5234    郭靖    出纳  5566.0   2000     NaN   10\n",
       "12  5566   宋远桥   会计师  7800.0   4000  1000.0   10\n",
       "13  7800   张三丰    总裁     NaN   9000  1200.0   20\n",
       "15  9600   王大锤   程序员  9800.0   8000   600.0   20\n",
       "17  9800    骆昊   架构师  7800.0  30000  5000.0   20\n",
       "18  9900   陈小刀   分析师  9800.0  10000  1200.0   20"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 以多列为依据删除重复值\n",
    "all_emp_df.drop_duplicates(['ename', 'job'], inplace=True)\n",
    "all_emp_df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a492ff40-3244-47d3-b32b-c8dacba4a390",
   "metadata": {},
   "source": [
    "### 异常值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "125d1675-4649-4e0b-9d6d-3e084defbab3",
   "metadata": {},
   "source": [
    "### 预处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "6bf259ba-20de-408f-a428-8b076eedc9d0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1945 entries, 0 to 1944\n",
      "Data columns (total 5 columns):\n",
      " #   Column  Non-Null Count  Dtype         \n",
      "---  ------  --------------  -----         \n",
      " 0   销售日期    1945 non-null   datetime64[ns]\n",
      " 1   销售区域    1945 non-null   object        \n",
      " 2   销售渠道    1945 non-null   object        \n",
      " 3   品牌      1945 non-null   object        \n",
      " 4   销售数量    1945 non-null   int64         \n",
      "dtypes: datetime64[ns](1), int64(1), object(3)\n",
      "memory usage: 76.1+ KB\n"
     ]
    }
   ],
   "source": [
    "sales_df = pd.read_excel(\n",
    "    'data/2020年销售数据.xlsx',\n",
    "    sheet_name='Sheet1',\n",
    "    usecols=['销售日期', '销售区域', '销售渠道', '品牌', '销售数量']\n",
    ")\n",
    "sales_df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "a029b099-6ed8-4e5f-9190-97a83e1802f9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>销售日期</th>\n",
       "      <th>销售区域</th>\n",
       "      <th>销售渠道</th>\n",
       "      <th>品牌</th>\n",
       "      <th>销售数量</th>\n",
       "      <th>月份</th>\n",
       "      <th>季度</th>\n",
       "      <th>星期</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>上海</td>\n",
       "      <td>拼多多</td>\n",
       "      <td>八匹马</td>\n",
       "      <td>83</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>上海</td>\n",
       "      <td>抖音</td>\n",
       "      <td>八匹马</td>\n",
       "      <td>29</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>上海</td>\n",
       "      <td>天猫</td>\n",
       "      <td>八匹马</td>\n",
       "      <td>85</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>上海</td>\n",
       "      <td>天猫</td>\n",
       "      <td>八匹马</td>\n",
       "      <td>14</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>上海</td>\n",
       "      <td>天猫</td>\n",
       "      <td>皮皮虾</td>\n",
       "      <td>61</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1940</th>\n",
       "      <td>2020-12-30</td>\n",
       "      <td>北京</td>\n",
       "      <td>京东</td>\n",
       "      <td>花花姑娘</td>\n",
       "      <td>26</td>\n",
       "      <td>12</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1941</th>\n",
       "      <td>2020-12-30</td>\n",
       "      <td>福建</td>\n",
       "      <td>实体</td>\n",
       "      <td>八匹马</td>\n",
       "      <td>97</td>\n",
       "      <td>12</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1942</th>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>福建</td>\n",
       "      <td>实体</td>\n",
       "      <td>花花姑娘</td>\n",
       "      <td>55</td>\n",
       "      <td>12</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1943</th>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>福建</td>\n",
       "      <td>抖音</td>\n",
       "      <td>八匹马</td>\n",
       "      <td>59</td>\n",
       "      <td>12</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1944</th>\n",
       "      <td>2020-12-31</td>\n",
       "      <td>福建</td>\n",
       "      <td>天猫</td>\n",
       "      <td>八匹马</td>\n",
       "      <td>27</td>\n",
       "      <td>12</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1945 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           销售日期 销售区域 销售渠道    品牌  销售数量  月份  季度  星期\n",
       "0    2020-01-01   上海  拼多多   八匹马    83   1   1   2\n",
       "1    2020-01-01   上海   抖音   八匹马    29   1   1   2\n",
       "2    2020-01-01   上海   天猫   八匹马    85   1   1   2\n",
       "3    2020-01-01   上海   天猫   八匹马    14   1   1   2\n",
       "4    2020-01-01   上海   天猫   皮皮虾    61   1   1   2\n",
       "...         ...  ...  ...   ...   ...  ..  ..  ..\n",
       "1940 2020-12-30   北京   京东  花花姑娘    26  12   4   2\n",
       "1941 2020-12-30   福建   实体   八匹马    97  12   4   2\n",
       "1942 2020-12-31   福建   实体  花花姑娘    55  12   4   3\n",
       "1943 2020-12-31   福建   抖音   八匹马    59  12   4   3\n",
       "1944 2020-12-31   福建   天猫   八匹马    27  12   4   3\n",
       "\n",
       "[1945 rows x 8 columns]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 处理时间\n",
    "sales_df['月份'] = sales_df['销售日期'].dt.month\n",
    "sales_df['季度'] = sales_df['销售日期'].dt.quarter\n",
    "sales_df['星期'] = sales_df['销售日期'].dt.weekday\n",
    "sales_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "4f2496eb-5100-4a18-b006-e43e66fceaa5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 3140 entries, 0 to 3139\n",
      "Data columns (total 4 columns):\n",
      " #   Column           Non-Null Count  Dtype \n",
      "---  ------           --------------  ----- \n",
      " 0   city             3140 non-null   object\n",
      " 1   companyFullName  3140 non-null   object\n",
      " 2   positionName     3140 non-null   object\n",
      " 3   salary           3140 non-null   object\n",
      "dtypes: object(4)\n",
      "memory usage: 98.3+ KB\n"
     ]
    }
   ],
   "source": [
    "jobs_df = pd.read_csv(\n",
    "    'data/某招聘网站招聘数据.csv',\n",
    "    usecols=['city', 'companyFullName', 'positionName', 'salary']\n",
    ")\n",
    "jobs_df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "ce565f16-b9ca-4915-a4a0-de49dd134b0b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>city</th>\n",
       "      <th>companyFullName</th>\n",
       "      <th>positionName</th>\n",
       "      <th>salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>北京</td>\n",
       "      <td>达疆网络科技（上海）有限公司</td>\n",
       "      <td>数据分析岗</td>\n",
       "      <td>15k-30k</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>北京</td>\n",
       "      <td>北京音娱时光科技有限公司</td>\n",
       "      <td>数据分析</td>\n",
       "      <td>10k-18k</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>北京</td>\n",
       "      <td>北京千喜鹤餐饮管理有限公司</td>\n",
       "      <td>数据分析</td>\n",
       "      <td>20k-30k</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>北京</td>\n",
       "      <td>吉林省海生电子商务有限公司</td>\n",
       "      <td>数据分析</td>\n",
       "      <td>33k-50k</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>北京</td>\n",
       "      <td>韦博网讯科技（北京）有限公司</td>\n",
       "      <td>数据分析</td>\n",
       "      <td>10k-15k</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  city companyFullName positionName   salary\n",
       "0   北京  达疆网络科技（上海）有限公司        数据分析岗  15k-30k\n",
       "1   北京    北京音娱时光科技有限公司         数据分析  10k-18k\n",
       "2   北京   北京千喜鹤餐饮管理有限公司         数据分析  20k-30k\n",
       "3   北京   吉林省海生电子商务有限公司         数据分析  33k-50k\n",
       "4   北京  韦博网讯科技（北京）有限公司         数据分析  10k-15k"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "jobs_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "07bea6ff-ce59-455a-8691-5260330e0a39",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1515, 4)"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 筛选\n",
    "jobs_df = jobs_df[jobs_df.positionName.str.contains('数据分析')]\n",
    "jobs_df.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "e3b1685a-12e7-45b5-80e6-698a714f8eb4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>15</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>33</td>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3065</th>\n",
       "      <td>8</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3069</th>\n",
       "      <td>6</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3070</th>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3071</th>\n",
       "      <td>6</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3088</th>\n",
       "      <td>8</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1515 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       0   1\n",
       "0     15  30\n",
       "1     10  18\n",
       "2     20  30\n",
       "3     33  50\n",
       "4     10  15\n",
       "...   ..  ..\n",
       "3065   8  10\n",
       "3069   6  10\n",
       "3070   2   4\n",
       "3071   6  12\n",
       "3088   8  12\n",
       "\n",
       "[1515 rows x 2 columns]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 通过正则从字符串提取数据\n",
    "jobs_df.salary.str.extract(r'(\\d+)[kK]?-(\\d+)[kK]?')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "e6853d06-349c-45c6-88ca-c9c464fa632f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       22.5\n",
       "1       14.0\n",
       "2       25.0\n",
       "3       41.5\n",
       "4       12.5\n",
       "        ... \n",
       "3065     9.0\n",
       "3069     8.0\n",
       "3070     3.0\n",
       "3071     9.0\n",
       "3088    10.0\n",
       "Length: 1515, dtype: float64"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 将字符串中提取的数据转换为数字\n",
    "temp_df = jobs_df.salary.str.extract(r'(\\d+)[kK]?-(\\d+)[kK]?').map(int)\n",
    "temp_df.apply(np.mean, axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "44f87a2a-4c8a-4a00-85b9-6806f3fbc942",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>city</th>\n",
       "      <th>companyFullName</th>\n",
       "      <th>positionName</th>\n",
       "      <th>salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>北京</td>\n",
       "      <td>达疆网络科技（上海）有限公司</td>\n",
       "      <td>数据分析岗</td>\n",
       "      <td>22.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>北京</td>\n",
       "      <td>北京音娱时光科技有限公司</td>\n",
       "      <td>数据分析</td>\n",
       "      <td>14.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>北京</td>\n",
       "      <td>北京千喜鹤餐饮管理有限公司</td>\n",
       "      <td>数据分析</td>\n",
       "      <td>25.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>北京</td>\n",
       "      <td>吉林省海生电子商务有限公司</td>\n",
       "      <td>数据分析</td>\n",
       "      <td>41.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>北京</td>\n",
       "      <td>韦博网讯科技（北京）有限公司</td>\n",
       "      <td>数据分析</td>\n",
       "      <td>12.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  city companyFullName positionName  salary\n",
       "0   北京  达疆网络科技（上海）有限公司        数据分析岗    22.5\n",
       "1   北京    北京音娱时光科技有限公司         数据分析    14.0\n",
       "2   北京   北京千喜鹤餐饮管理有限公司         数据分析    25.0\n",
       "3   北京   吉林省海生电子商务有限公司         数据分析    41.5\n",
       "4   北京  韦博网讯科技（北京）有限公司         数据分析    12.5"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "jobs_df['salary'] = temp_df.apply(np.mean, axis=1)\n",
    "jobs_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9f89133b-bed6-43e0-91d8-5f0fbbc2635c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
